import _custom from '@/common/_custom.js'
import _data from '@/common/_data.js'
import moment from 'moment'

function getTableSuffix(date) {
	let year = (moment(date).year() + '').substr(2)
	let month = moment(date).month() + 1
	month = month < 10 ? '0' + month : month
	let tablesuffix = _data.localData('obscode') + "_" + year + month
	return tablesuffix
}

export function getDayData(date,cnlcode) {
	if(cnlcode == 'Y2G2M03LL') {//每日进口水量
		_custom.getCnlDataList({
			apiname: 'getCnlDataHourAvgMergeList',
			apiparam: {
				startdate: date,
				enddate: date,
				mergetag: 1,
				tablesuffix: getTableSuffix(date),
				cnlcode: cnlcode,
			}
		})
	} else if(cnlcode == 'P1E1M06SSL') {//每日出口水量
		_custom.getCnlDataList({
			apiname: 'getCnlDataHourAvgMergeList',
			apiparam: {
				startdate: date,
				enddate: date,
				mergetag: 2,
				tablesuffix: getTableSuffix(date),
				cnlcode: cnlcode,
			}
		})
	} else {
		_custom.getCnlDataList({
			apiname: 'getCnlDataHourAvgList',
			apiparam: {
				tablesuffix: getTableSuffix(date),
				cnlcode: cnlcode,
				startdate: date,
				enddate: date
			}
		})
	}
}
let cnlcodes1 = ['P1E1M06SSL','Y2G2M03LL','P1E1M01CKCOD','Y1J1M01JKCOD'];
let cnlcodes2 = ['P1E1M05CKPH','P1E1M03CKZD','Y1J1M03JKZD','P1E1M04CKZL','Y1J1M04JKZL','P1E1M02CKAD','Y1J1M02JKAD']
export function getDayData1(date) {
	for (let i = 0; i < cnlcodes1.length; i++) {
		if(cnlcodes1[i] == 'Y2G2M03LL') {//每日进口水量
			_custom.getCnlDataList({
				apiname: 'getCnlDataHourAvgMergeList',
				apiparam: {
					startdate: date,
					enddate: date,
					mergetag: 1,
					tablesuffix: getTableSuffix(date),
					cnlcode: cnlcodes1[i],
				}
			})
		} else if(cnlcodes1[i] == 'P1E1M06SSL') {//每日出口水量
			_custom.getCnlDataList({
				apiname: 'getCnlDataHourAvgMergeList',
				apiparam: {
					startdate: date,
					enddate: date,
					mergetag: 2,
					tablesuffix: getTableSuffix(date),
					cnlcode: cnlcodes1[i],
				}
			})
		} else {
			_custom.getCnlDataList({
				apiname: 'getCnlDataHourAvgList',
				apiparam: {
					tablesuffix: getTableSuffix(date),
					cnlcode: cnlcodes1[i],
					startdate: date,
					enddate: date
				}
			})
		}
	}
}
export function getDayData2(date) {
	for (let i = 0; i < cnlcodes2.length; i++) {
		_custom.getCnlDataList({
			apiname: 'getCnlDataHourAvgList',
			apiparam: {
				tablesuffix: getTableSuffix(date),
				cnlcode: cnlcodes2[i],
				startdate: date,
				enddate: date
			}
		})
	}
}

export function getMonthData1(date) {
	for (let i = 0; i < cnlcodes1.length; i++) {
		if(cnlcodes1[i] == 'Y2G2M03LL') {//每月进口水量
			_custom.getCnlDataList({
				apiname: 'getCnlDataDaySumMergeList',
				apiparam: {
					mergetag: 1,
					tablesuffix: getTableSuffix(date),
					cnlcode: cnlcodes1[i],
				}
			})
		} else if(cnlcodes1[i] == 'P1E1M06SSL') {//每月出口水量
			_custom.getCnlDataList({
				apiname: 'getCnlDataDaySumMergeList',
				apiparam: {
					mergetag: 2,
					tablesuffix: getTableSuffix(date),
					cnlcode: cnlcodes1[i],
				}
			})
		} else {
			_custom.getCnlDataList({
				apiname: 'getCnlDataDayAvgList',
				apiparam: {
					tablesuffix: getTableSuffix(date),
					cnlcode: cnlcodes1[i],
				}
			})
		}
	}
}
export function getMonthData2(date) {
	for (let i = 0; i < cnlcodes2.length; i++) {
		_custom.getCnlDataList({
			apiname: 'getCnlDataDayAvgList',
			apiparam: {
				tablesuffix: getTableSuffix(date),
				cnlcode: cnlcodes2[i],
			}
		})
	}
}

export function getYearData1(date) {
	for (let i = 0; i < cnlcodes1.length; i++) {
		if(cnlcodes1[i] == 'Y2G2M03LL') {//每年进口水量
			_custom.getCnlDataList({
				apiname: 'getCnlDataMonthSumMergeList',
				apiparam: {
					mergetag: 1,
					obsyear: date,
					cnlcode: cnlcodes1[i],
				}
			})
		} else if(cnlcodes1[i] == 'P1E1M06SSL') {//每年出口水量
			_custom.getCnlDataList({
				apiname: 'getCnlDataMonthSumMergeList',
				apiparam: {
					mergetag: 2,
					obsyear: date,
					cnlcode: cnlcodes1[i],
				}
			})
		} else {
			_custom.getCnlDataList({
				apiname: 'getCnlDataMonthAvgList',
				apiparam: {
					obsyear: date,
					cnlcode: cnlcodes1[i],
				}
			})
		}
		
	}
}
export function getYearData2(date) {
	for (let i = 0; i < cnlcodes2.length; i++) {
		_custom.getCnlDataList({
			apiname: 'getCnlDataMonthAvgList',
			apiparam: {
				obsyear: date,
				cnlcode: cnlcodes2[i],
			}
		})
	}
}